***************
* Information *
***************

* This do-file reproduces codings and analyses for the Danish study in the manuscript, Reproductive
* Interests and Dimensions of Political Ideology, published in Evolution and 
* Human Behavior.
* The do-file is designed to work with the data file, Replication Data - Danish Study.dta

*************
* Recodings *
*************

* Generation of SOI measure

mvdecode q16_1_resp q16_2_resp q16_3_resp, mv(99)
alpha q16_1_resp q16_2_resp q16_3_resp, gen(SOIatt)
zscore SOIatt

mvdecode q17, mv(9)
zscore q17

gen q18_n1rc=q18_n1
replace q18_n1rc=9 if q18_n1>9

gen q19_n1rc=q19_n1
replace q19_n1rc=15 if q19_n1>15

gen q20_n1rc=q20_n1
replace q20_n1rc=15 if q20_n1>15

zscore q18_n1rc q19_n1rc q20_n1rc

alpha z_q18_n1rc z_q19_n1rc z_q20_n1rc z_q17 z_SOIatt, gen(SOI) casewise
sum SOI
gen SOI_01 = (SOI - r(min))/(r(max) - r(min))
sum SOI_01

* Generation of RWA measure

alpha q25_1_resp q25_2_resp q25_3_resp q25_4_resp q25_5_resp q25_6_resp, gen(RWAx)

gen RWA=RWAx*-1
sum RWA
gen RWA01=(RWA+4.333333)/(4.333333+1.166667)
sum RWA01

* Generation of SDO measure

alpha q24_1_resp q24_2_resp q24_3_resp q24_4_resp q24_5_resp q24_6_resp, gen(SDOx)

gen SDO=SDOx*-1
sum SDO
gen SDO01=(SDO+3)/6
sum SDO01

* Generation of ideological self-placement

ta q23
gen ideo01=(q23-1)/6
sum ideo01

* Generation of gender

ta q3
gen female=q3-1

* Genderation of age

ta q4
gen age01=q4-18/(79-18)
sum age01

* Generation of religiosity 

gen reli01=(q7-1)/6

* Generation of education

ta q9
mvdecode q9, mv(7 8)
gen edux=(q9-1)/5
gen edu01=(edux-1)*-1
sum edu01

* Generation of stable relationship

ta q5
ta q5, nolabel
gen norel01=q5-1

* Generation of subjective social status

ta q27_new
gen ladder01=(((q27_new-1)/10)-1)*-1
sum ladder01
cor q27_new ladder01

* Generation of subjective mate value

ta q14
mvdecode q14, mv(12)
gen matevalue01=(q14-1)/10
sum matevalue01

* Generation of mate preferences

gen Commit=(q21_5_resp- q21_6_resp+10)/20
gen PhysAtt= (q21_1_resp-q21_2_resp+10)/20
gen SexExp= (q21_3_resp- q21_4_resp+10)/20
gen Faith= (q21_7_resp- q21_8_resp+10)/20
gen Ambit= (q21_9_resp- q21_10_resp+10)/20
gen Wealth= (q21_12_resp- q21_11_resp+10)/20
gen FamOr= (q21_13_resp- q21_14_resp+10)/20

* Generation of alternative mate preference measures

factor q21_5_resp q21_6_resp q21_7_resp q21_8_resp q21_3_resp q21_4_resp q21_12_resp q21_11_resp q21_9_resp q21_10_resp q21_13_resp q21_14_resp q21_1_resp q21_2_resp, pcf
predict fac1u fac2u fac3u

foreach var of varlist fac1u fac2u fac3u {
egen `var'min = min(`var')
egen `var'max = max(`var')
gen `var'01 = (`var' - `var'min) / (`var'max - `var'min)
drop `var'max `var'min
}

gen longrich=fac1u01
gen indisc=fac2u01
gen longpoor=fac3u01

************
* Analyses *
************

*** Testing H1 and H2

* Generation of Figure 1, Panel A

reg SOI_01 ideo01 female age01 reli01 edu01 norel01
margins, dydx(ideo01) level(95)
estimates store m1
reg  SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01
margins, dydx(RWA01) level(95)
estimates store m2
reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01
margins, dydx(SDO01) level(95)
estimates store m3

coefplot (m1, keep("ideo01")) (m2, keep("RWA01")) (m3, keep("SDO01")), ///
recast(bar) barw(.70) ciopts(recast(rcap) lpattern(dash) lcolor(black)) citop msize(medlarge) vertical yscale(range(-.4 .4)) ///
title("A. Danish Representative Sample") ylabel(-.4(.10).4, nogrid) yline(0, lstyle(foreground)) xlabel(none) ytitle("Association with SOI") ///
legend (order(1 3 5) ///
	label(1 "Ideological Self-Placement") ///
	label(3 "RWA") ///
	label(5 "SDO") col(1)) ///
	scheme(s2mono) graphregion(lcolor(black) fcolor(white))
graph display, ysize(3) xsize(2.5)
  
* Generation of Table 1, Models 1+2

eststo clear
eststo: reg SOI_01 ideo01 female age01 reli01 edu01 norel01
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01
esttab, b(%5.2f) se(%5.2f), using Table1dk.rtf, replace onecell star(* 0.05 ** 0.01 *** 0.001) wide constant r2
eststo clear

* Generation of Table A1, Models 1+2

eststo clear
eststo: reg RWA01 SOI_01 SDO01 female age01 reli01 edu01 norel01
eststo: reg SDO01 SOI_01 RWA01 female age01 reli01 edu01 norel01
esttab, b(%5.2f) se(%5.2f), using TableA1dk.rtf, replace onecell star(* 0.05 ** 0.01 *** 0.001) wide constant r2
eststo clear

* Testing H1 and H2 using SEM

gen q25_1_respRC=-1*q25_1_resp

sem (SOI_01 <- SDO RWA) /*
*/ (SDO -> q24_1_resp q24_2_resp q24_3_resp q24_4_resp q24_5_resp q24_6_resp) (RWA -> q25_1_respRC q25_2_resp q25_3_resp q25_4_resp q25_5_resp q25_6_resp), nocaps latent(RWA SDO) standardize var(RWA@1) var(SDO@1) cov(SDO*RWA) iterate(1000)

matrix b = e(b)

sem (SOI_01 <- SDO RWA female age01 reli01 edu01 norel01) /*
*/ (SDO -> q24_1_resp q24_2_resp q24_3_resp q24_4_resp q24_5_resp q24_6_resp) (RWA -> q25_1_respRC q25_2_resp q25_3_resp q25_4_resp q25_5_resp q25_6_resp), nocaps latent(RWA SDO) standardize var(RWA@1) var(SDO@1) cov(SDO*RWA) iterate(1000)

*** Testing H3 and H4

* Generation of Table A3, Model 1

eststo clear
eststo: reg SOI_01 RWA01 SDO01 female c.RWA01##c.female c.SDO01##c.female age01 reli01 edu01 norel01
esttab, b(%5.2f) se(%5.2f), using TableA3dk.rtf, replace onecell star(* 0.05 ** 0.01 *** 0.001) wide constant r2
eststo clear

*** Testing H5

* Generation of Table A4

eststo clear
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01 ladder01 c.RWA01##c.ladder01 c.SDO01##c.ladder01
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01 ladder01 c.RWA01##c.ladder01 c.SDO01##c.ladder01 if female==0
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01 ladder01 c.SDO01##c.ladder01##c.female
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01 matevalue01 c.RWA01##c.matevalue01 c.SDO01##c.matevalue01
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01 matevalue01 c.RWA01##c.matevalue01 c.SDO01##c.matevalue01 if female==0
eststo: reg SOI_01 RWA01 SDO01 female age01 reli01 edu01 norel01 matevalue01 c.SDO01##c.matevalue01##c.female
esttab, b(%5.2f) se(%5.2f), using TableA4.rtf, replace onecell star(* 0.05 ** 0.01 *** 0.001) wide constant r2
eststo clear

*** Testing H6 and H7

* Generation of results for Table 2

khb reg SOI_01 RWA01 SDO01 || Commit Faith SexExp Wealth Ambit FamOr PhysAtt, concomitant(female age01 reli01 edu01 norel01) disentangle verbose

* Generation of p-values for stars in Table 2

display normalden(-.0175283/.0075202)
display normalden(-.0239385/.0057829)
display normalden(-.0128746/.0043265) 

display normalden(.0326586/.0072061)
display normalden(.0130404/.0044474)
display normalden(.0181831/.0061011)

* Additional analysis related to H6 and H7: Separating males and females (reported in footnote)

khb reg SOI_01 SDO01 || Commit Faith SexExp Wealth Ambit FamOr PhysAtt if female==0, concomitant(RWA01 age01 reli01 edu01 norel01) disentangle
display normalden(.0369879/.0116636)
display normalden(.0270687/.0105682)

khb reg SOI_01 RWA01 || Commit Faith SexExp Wealth Ambit FamOr PhysAtt if female==1, concomitant(SDO01 age01 reli01 edu01 norel01) disentangle
display normalden(-.0237317/.0088416)
display normalden(-.0284051/.0087908)                  
display normalden(-.0284225/.0086144)      

* Additional analysis related to H6 and H7: Generation of results for Table A8

factor q21_5_resp q21_6_resp q21_7_resp q21_8_resp q21_3_resp q21_4_resp q21_12_resp q21_11_resp q21_9_resp q21_10_resp q21_13_resp q21_14_resp q21_1_resp q21_2_resp, pcf

corr SOI_01 longrich indisc longpoor

* Additional analysis related to H6 and H7: Generation of results for Table A9

khb reg SOI_01 RWA01 SDO01 || longrich indis longpoor, concomitant(female age01 reli01 edu01 norel01) disentangle verbose

display normalden(-.0244835/.0061237)
display normalden(-.0338373/.0066702)

display normalden(.022413/.0054824)
display normalden(.0517134/.0074776)

